define [
  'controllers/base/controller'
  'views/movimento/index_view'
  'views/movimento/form_view'
  'models/movimento_model'
  'collections/movimento_collection'
], ->

  'use strict'

  Controller            = require 'controllers/base/controller'
  IndexView             = require 'views/movimento/index_view'
  FormView              = require 'views/movimento/form_view'
  MovimentoModel        = require 'models/movimento_model'
  MovimentoCollection   = require 'collections/movimento_collection'

  class MovimentoController extends Controller

    index: ->
      @collection = new MovimentoCollection
      @view       = new IndexView collection: @collection

    create: ->
      @model = new MovimentoModel
      @view  = new FormView model: @model
      @_setupHistoryBack()

    edit: (params) ->
      @model = new MovimentoModel id: params.id
      @view  = new FormView model: @model
      @_setupHistoryBack()

    # Helpers
    # =============================================================

    _setupHistoryBack: ->
      @view.on 'model:saved', =>
        @publishEvent 'feedback:success', 'Movimento salvo com sucesso'
        @redirectTo url: 'movimento'
